Use case: COMP comparing by interruption ¶
Description of usage ¶
|
Operation |
HAL1 |
HAL2 |
|---|---|---|
|
Start comparing |
Activate Comparator analog features using
|
Activate Comparator analog features using
|
|
Comparator output trigger callback |
Register the callback using HAL_COMP_RegisterCallback(), or implement HAL_COMP_TriggerCallback(). |
Register the callback using HAL_COMP_RegisterOutputTriggerCallback(), or implement HAL_COMP_OutputTriggerCallback(). |
|
Retrieve comparing result |
Retrieve comparing results using
|
Retrieve comparing results using
|
|
Loop for multiple iterations |
Possible multiple iterations if the comparator output has changed since the last read. |
Possible multiple iterations if the comparator output has changed since the last read. |
|
Stop comparing |
Stop Comparator analog features using
|
Stop Comparator analog features using
|
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
int main(void)
{
/*initialize and configure your comparing input*/
/* Start the COMP */
HAL_COMP_Start_IT(&comp1);
while(HAL_COMP_GetOutputLevel(hcomp) != COMP_OUTPUT_LEVEL_HIGH)
{
/* generate voltage on comparator inputs */
/* add a Wait time for voltage stabilization*/
}
/* Stop the COMP */
HAL_COMP_Stop_IT(&comp1);
}
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef *hcomp)
{
if (hcomp->Instance == COMP1)
{
/* Handle the comparator event here */
if (HAL_COMP_GetOutputLevel(hcomp) == COMP_OUTPUT_LEVEL_HIGH)
{
/* Comparator output is high */
}
else
{
/* Comparator output is low */
}
}
}
|
int main(void)
{
/*initialize and configure your comparing input*/
/* Start the COMP */
HAL_COMP_Start_IT(&comp1);
while(HAL_COMP_GetOutputLevel(hcomp) != COMP_OUTPUT_LEVEL_HIGH)
{
/* generate voltage on comparator inputs */
/* add a Wait time for voltage stabilization*/
}
/* Stop the COMP */
HAL_COMP_Stop_IT(&comp1);
}
void HAL_COMP_OutputTriggerCallback(COMP_HandleTypeDef *hcomp)
{
/* Handle the comparator event here */
if (HAL_COMP_GetOutputLevel(hcomp) == HAL_COMP_OUTPUT_LEVEL_HIGH)
{
/* Comparator output is high */
}
else
{
/* Comparator output is low */
}
}
|
Key changes ¶
No major changes between HAL1 and HAL2. The only change is the renaming of the trigger callback.
![@startuml
title: COMP basic operation using programming model: interruption
participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI
participant "System HW interruption" as interruption
group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_Start_IT()
COMP->COMP : Enable selected interruptions\nActivate comparator analog features
COMP->appli
loop#lightgrey Possible multiple iterations
interruption <[#red]-x? : <font color=red><b>COMP IRQ event
interruption -> appli_IRQ : COMPx_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> COMP : HAL_COMP_IRQHandler()
COMP -> EXTI : Manage EXTI line flag
COMP <- EXTI
COMP -> appli_IRQ: <font color=blue><b> HAL_COMP_TriggerCallback()
appli_IRQ->COMP : HAL_COMP_GetOutputLevel()
COMP --> appli_IRQ: Logical level high/low
appli_IRQ -> interruption : (return from ISR)
deactivate appli_IRQ
end
appli->COMP : HAL_COMP_Stop_IT()
return
end
@enduml](../../../../../_images/plantuml-78acba521cf63fba30c524e90a8cd57f496e52af.png)
![@startuml
title: COMP basic operation using programming model: interruption
participant "User Application\n(thread mode)" as appli
participant "User Application\n(handler mode)" as appli_IRQ
participant "<font color=green><b>HAL COMP</b></font>" as COMP
participant "HAL EXTI" as EXTI
participant "System HW interruption" as interruption
group#Bisque #Linen COMP operation
appli->COMP : HAL_COMP_Start_IT()
COMP->COMP : Enable selected interruptions\nActivate comparator analog features
COMP->appli
hnote over COMP: global_state=ACTIVE
loop#lightgrey Possible multiple iterations
interruption <[#red]-x? : <font color=red><b>COMP IRQ event
interruption -> appli_IRQ : COMPx_IRQHandler()
activate appli_IRQ #DarkSalmon
appli_IRQ -> COMP : HAL_COMP_IRQHandler()
COMP -> EXTI : Manage EXTI line flag
COMP <- EXTI
COMP -> appli_IRQ: <font color=blue><b> HAL_COMP_OutputTriggerCallback()
appli_IRQ->COMP : HAL_COMP_GetOutputLevel()
COMP --> appli_IRQ: Logical level high/low
appli_IRQ -> interruption : (return from ISR)
deactivate appli_IRQ
end
appli->COMP : HAL_COMP_Stop_IT()
return
end
@enduml](../../../../../_images/plantuml-c036e79c56019e061c3732cb152bce2825ec9e4e.png)